package cn.yotta.user.api.params.login;

import cn.yotta.common.utils.param.AssertUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.function.Supplier;

import static cn.yotta.user.api.error.UserCommonErrorCode.USER_NAME_MUST_NOT_NULL;

/**
 * @author wyaoyao
 * @date 2022/11/8 10:33
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@ToString(callSuper = true)
@ApiModel("用户名密码登录请求参数")
public class LoginByUsernamePasswordRequest extends BaseLoginByPasswordRequest {

    @ApiModelProperty(value = "用户名", required = true)
    private String username;


    @Override
    public void checkValid() {
        super.checkValid();
        AssertUtil.notBlank(username, USER_NAME_MUST_NOT_NULL.getCode());
    }

    @Override
    public Supplier<String> getPrincipal() {
        return this::getUsername;
    }
}
